package com.icloud.article.boot.controller.app;


import com.icloud.article.boot.dto.ArticleHotDetDto;
import com.icloud.article.boot.dto.ArticleHotDto;
import com.icloud.article.boot.dto.ArticleHotPageDto;
import com.icloud.article.boot.dto.ConsumptionDto;
import com.icloud.article.boot.service.HotArticleService;
import com.icloud.article.boot.vo.ArticleVo;
import com.icloud.article.boot.vo.ConsumptionVo;
import com.icloud.common.core.api.CommonResult;
import com.icloud.common.web.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "App热帖接口")
@RequestMapping("/app/hot")
@RequiredArgsConstructor
public class AppHotArticleController {

    private final HotArticleService hotArticleService;

    @ApiOperation("上热帖")
    @PostMapping("")
    @ResponseBody
    public CommonResult<Boolean> hot(@Validated @RequestBody ArticleHotDto dto){
        return CommonResult.success(hotArticleService.hot(dto));
    }

    @ApiOperation("热帖消耗量")
    @PostMapping("/consumption")
    @ResponseBody
    public CommonResult<ConsumptionVo> consumption(@Validated @RequestBody ConsumptionDto dto){
        return CommonResult.success(hotArticleService.consumption(dto));
    }

    @ApiOperation("分页查询热帖(显示作者头像和昵称)")
    @PostMapping("/page")
    @ResponseBody
    public CommonResult<PageVO<ArticleVo>> page(@Validated @RequestBody ArticleHotPageDto dto){
        return CommonResult.success(hotArticleService.hotPage(dto));
    }

    @ApiOperation("热帖详情,支持热帖仅浏览一次后就不再在热帖列表中显示的功能")
    @PostMapping("/detail")
    @ResponseBody
    public CommonResult<ArticleVo> detail(@Validated @RequestBody ArticleHotDetDto dto){
        return CommonResult.success(hotArticleService.detail(dto));
    }
}
